<?php
// +----------------------------------------------------------------------
// | [ api-yun.lib ] wo.pan
// +----------------------------------------------------------------------
// | Author: 北菜菜 <1440802@qq.com>
// +----------------------------------------------------------------------

namespace wopan\lib\channel;

use wopan\lib\WoPanAES;
use wopan\lib\WoPanChannel;

/**
 * Class ApiUser
 */
class ApiUser extends WoPanChannel
{
    public static $channel = 'api-user';

    public function queryFamilyGroups()
    {
        $response = $this->request("QueryFamilyGroups", [
            "clientId" => $this->clientId,
            "param"   => WoPanAES::encrypt(json_encode(['accessToken' => $this->accessToken]), $this->clientSecret),
            "secret"  => true
        ]);
        $response->data = WoPanAES::decrypt($response->data, $this->clientSecret);
        $response->data = json_decode($response->data, true);
        return $response;
    }
    
    public function appLoginV2($phone, $password, $uuid = '', $verifyCode = '')
    {
        $clientSecret = $this->clientSecret;
        $response = $this->request("AppLoginV2", [
            "clientId" => $this->clientId,
            "param"   => WoPanAES::encrypt(json_encode(compact('phone', 'password', 'uuid', 'verifyCode', 'clientSecret')), $this->clientSecret),
            "secret"  => true
        ]);
        $response->data['expires_time'] = time() + $response->data['expires_in'];
        return $response;
    }
}
